using System;
using System.Collections.Generic;
using System.Text;

namespace OnlinePlots.Plots.Scales
{
    /// <summary>
    /// Represents a linear scale where [scaled value] = coeff * [uncaled value] + offest
    /// </summary>
    public class LinearScale : Scale
    {
        private double coeff = 1;
        private double offset = 0;

        /// <summary>
        /// Creates a new instance of a linear scale with specified coeff and offset = 0
        /// </summary>
        /// <param name="coeff">Linear quotient of scaling</param>
        public LinearScale(double coeff)
        {
            this.coeff = coeff;
        }

        /// <summary>
        /// Creates a new instance of a linear scale with specified coeff and offset
        /// </summary>
        /// <param name="coeff">Linear quotient of scaling</param>
        /// <param name="offset">Offset of scaling</param>
        public LinearScale(double coeff, double offset)
            : this(coeff)
        {
            this.offset = offset;
        }

        /// <summary>
        /// Gets or sets linear quotient of scaling
        /// </summary>
        public double Coeff
        {
            get { return coeff; }
            set { coeff = value; }
        }

        /// <summary>
        /// Gets or sets offset of scaling
        /// </summary>
        public double Offset
        {
            get { return offset; }
            set { offset = value; }
        }
        
        public override double GetScaledValue(double initialValue)
        {
            return initialValue * Coeff + Offset;
        }

        public override double GetUnscaledValue(double scaledValue)
        {
            return (scaledValue - Offset) / Coeff;
        }
    }
}
